package com.cxy.ch1;

import java.util.concurrent.ExecutionException;

/**
 * 
 * @ClassName: DaemonThread
 * @Description: TODO(守护线程的使用)
 * @author 菜徐鸭
 * @date 2020年4月12日
 *
 */
public class DaemonThread {
	private static class UseThread extends Thread {
		@Override
		public void run() {
			try {
				while (!isInterrupted()) {
					System.out.println(Thread.currentThread().getName() + " 我继承了Thread类.");
				}
				System.out.println(Thread.currentThread().getName() + " interrupt flag is " + isInterrupted());
			} finally {
				// 守护线程中finally不一定起作用
				System.out.println(" .............finally");
			}
		}
	}

	public static void main(String[] args) throws InterruptedException, ExecutionException {
		UseThread useThread = new UseThread();
		// useThread.setDaemon(true);
		useThread.start();
		Thread.sleep(5);
		useThread.interrupt();
	}
}
